package com.changebitmapcolor;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint;
import android.os.Bundle;
import android.widget.ImageView;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		ImageView image= (ImageView) findViewById(R.id.image);
		Bitmap bitmap= BitmapFactory.decodeResource(getResources(), R.drawable.image);
//		image.setImageBitmap(BitmapUtil.reflection(bitmap));
		image.setImageBitmap(changeImageColor(bitmap, android.R.color.holo_blue_dark));
	}
	
	public static Bitmap changeImageColor(Bitmap bitmap,int newColor){
       
      int width=bitmap.getWidth();
	    int height=bitmap.getHeight();
    	Bitmap grayImg = null;
	    try{
	    	grayImg = Bitmap.createBitmap(width,height, Bitmap.Config.ARGB_8888);
		    Canvas canvas = new Canvas(grayImg);
		    Paint paint = new Paint();
		    ColorMatrix colorMatrix = new ColorMatrix();
		    float[] colorArray = {1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0};
		    colorMatrix.setSaturation(0);
//		    colorMatrix.set(colorArray);
		    ColorMatrixColorFilter colorMatrixFilter = new ColorMatrixColorFilter(colorMatrix); 
		    paint.setColorFilter(colorMatrixFilter);
//		    paint.setColorFilter(new LightingColorFilter(Color.BLUE, newColor));//通过color控制图片颜色
		    canvas.drawBitmap(bitmap,0,0, paint);
		    bitmap.recycle();
	    }catch(Exception e) {
	    	e.printStackTrace();
	    }
	    return grayImg;
    }
}